/*************************************************

  Author:	Gideon Chen
  Version:	1.01
  Date:
   Description:
  Others:
  History:
    1. Date:
       Author:
       Modification:
    2. ...
*************************************************/
#ifndef  MSP430_IO
#define  MSP430_IO

#include "HW_mcu.h"
struct  PORT_X {
                    uchar  b0:1;
                    uchar  b1:1;
                    uchar  b2:1;
                    uchar  b3:1;
                    uchar  b4:1;
                    uchar  b5:1;
                    uchar  b6:1;
                    uchar  b7:1;
                };
struct  Flag_X {
                    uchar  b0:1;
                    uchar  BatteryLow:1;
                    uchar  b2:1;
                    uchar  b3:1;
                    uchar  b4:1;
                    uchar  b5:1;
                    uchar  b6:1;
                    uchar  TxBuffer_Empty:1;
                };
struct  PORT_1out {
                    uchar  b0:1;
                    uchar  b1:1;
                    uchar  b2:1;
                    uchar  b3:1;
                    uchar  b4:1;
                    uchar  b5:1;
                    uchar  b6:1;
                    uchar  b7:1;
                };

struct  PORT_1in {
                    uchar  b0:1;
                    uchar  b1:1;
                    uchar  b2:1;
                    uchar  b3:1;
                    uchar  b4:1;
                    uchar  b5:1;
                    uchar  b6:1;
                    uchar  b7:1;
                };
#define inP1   (*(volatile struct PORT_1in*)  0x0020)
#define outP1  (*(volatile struct PORT_1out*) 0x0021)
#define inP3   (*(volatile struct PORT_X*)    0x0018)
#define outP3  (*(volatile struct PORT_X*)    0x0019)
#define inP4   (*(volatile struct PORT_X*)    0x001c)
#define outP4  (*(volatile struct PORT_X*)    0x001d)
#define inP2    (*(volatile struct PORT_X*)   0x0028)
#define outP2  (*(volatile struct PORT_X*)    0x0029)
#define inP6   (*(volatile struct PORT_X*)    0x0034)
#define outP6   (*(volatile struct PORT_X*)   0x0035)


#define SPI0   (*(volatile struct Flag_X*)  0x0002)

#if    ADC_TYPE == CS5532
    #define ADCS    outP1.b0
    #define ADDIN   outP1.b2
    #define ADSCLK  outP1.b1
    #define ADDOUT  inP1.b3
#endif // #if    ADC_TYPE == CS5532

#if    ADC_TYPE == CS5460
    #define AD5460_RST  outP6.b7
    #define AD5460_IN    outP1.b2
    #define AD5460_CLK   outP1.b1
    #define AD5460_OUT   inP1.b3
    #define AD5460_INT        inP1.b0
#endif //#if    ADC_TYPE == CS5460

#if EEPROM_TYPE == EE93C66
    #define EE_CS     outP6.b0
    #define EE_DIN    outP6.b2
    #define EE_SCLK   outP6.b1
    #define EE_DOUT   inP6.b3
#endif // #if EEPROM_TYPE == EE93C66
#if EEPROM_TYPE == HT24C02
    #define   EE_SCLK  outP6.b1
    #define   EE_WP    outP6.b2
    #define   EE_DIN   inP6.b0
    #define   EE_DOUT   outP6.b0
    #define   EE_DATA_OUT     P6DIR |= BIT_0
    #define   EE_DATA_IN      P6DIR &= ~BIT_0
#endif


#define BEEP            outP2.b2
#define BEEP_EX         outP3.b4

#define BACKLIGHT    outP6.b6
#define    SWITCH          inP2.b1
#define    BATTERY_WAR1    inP6.b5
#define    BATTERY_WAR2    inP6.b4
#define    IO_CAL1         inP6.b3

#define RELAY_LO     outP3.b7
#define RELAY_OK     outP3.b6
#define RELAY_HI     outP3.b5

#define RELAY_ALARM  outP3.b4
#define SOFT_CAL       inP3.b7

/************ keys  *****************/
#define KEY_OUT1   outP2.b7
#define KEY_OUT2   outP3.b0
#define KEY_OUT3   outP3.b1
#define KEY_OUT4   outP3.b2
#define KEY_OUT5   outP3.b3

#define KEY_IN1    inP1.b4
#define KEY_IN2    inP1.b5
#define KEY_IN3    inP1.b6
#define KEY_IN4    inP1.b7
#define KEY_IN5    inP2.b6


#define BUZZER_ON()    do{\
                            BEEP = 1;\
                         }while(0)
#define BUZZER_OFF()   do{\
                            BEEP = 0;\
                         }while(0)

#define EX_BUZZER_ON()  do{\
                              BEEP_EX = 1;\
                          }while(0)
#define EX_BUZZER_OFF() do{\
                              BEEP_EX = 0;\
                          }while(0)

// #define POWER_ON()     do{outP2.b0=1;}while(0)
// #define POWER_OFF()    do{outP2.b0=0;}while(0)

#define POWER_ON()     outP2.b0=1
#define POWER_OFF()    outP2.b0=0

//#define GIEDisable {if(IntsDisableCount==0) {IntStatus=_BIC_SR(0x0008);} IntsDisableCount++;}
//#define GIEEnable {if(--IntsDisableCount==0&&(IntStatus&0x0008)) _EINT();}

#define GIEDisable() _BIC_SR(0x0008)
#define GIEEnable()  _EINT()
#endif

